//
//  SheetDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/6/29.
//

import SwiftUI

struct SheetDemo: View {
    
    @State var showSheet: Bool = false
    
    var body: some View {
        ZStack {
            Color.green
                .edgesIgnoringSafeArea(.all)
            
            Button {
                showSheet.toggle()
            } label: {
                Text("Button")
                    .foregroundColor(.green)
                    .font(.headline)
                    .padding(20)
                    .background(Color.white.cornerRadius(10))
            }
//            .sheet(isPresented: $showSheet) {
//                SecondScreen()
//            }
            .fullScreenCover(isPresented: $showSheet) {
                SecondScreen()
            }

        }
    }
}

struct SecondScreen: View {
    
    @Environment(\.presentationMode) var presentationMode
    
    var body: some View {
        ZStack(alignment: .topLeading) {
            Color.red
                .edgesIgnoringSafeArea(.all)
            
            Button {
//                showSheet.toggle()
                presentationMode.wrappedValue.dismiss()
            } label: {
//                Text("Button")
                Image(systemName: "xmark")
                    .foregroundColor(.white)
                    .font(.largeTitle)
                    .padding(20)
//                    .background(Color.white.cornerRadius(10))
            }
//            .sheet(isPresented: $showSheet) {
//                Text("Hello there")
//            }

        }
    }
    
}

#Preview {
    SheetDemo()
}
 
